Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider the translation scheme shown belowS ... Start Learning for Free
Consider the translation scheme shown below
S → T R
R → + T {print ('+');} R | ε
T → num {print (num.val);}
Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will print
  • a)
    9 + 5 + 2
  • b)
    9 5 + 2 +
  • c)
    9 5 2 + +
  • d)
    + + 9 5 2
Correct answer is option 'B'. Can you explain this answer?
Verified Answer
Consider the translation scheme shown belowS → T RR → + T ...
Let us make the parse tree for 9+5+2 in top down manner, left first derivation.
Steps:
1) Exapnd S->TR
2) apply T->Num...
3) apply R -> +T...
4) appy T->Num...
5) apply R-> +T..
6) apply T-> Num..
7) apply R-> epsilon
After printing through the print statement in the parse tree formed you will get the answer as 95+2+
View all questions of this test
Most Upvoted Answer
Consider the translation scheme shown belowS → T RR → + T ...
Explanation:

This translation scheme is used to translate an input string into a sequence of print statements. The input string consists of a series of numbers separated by whitespace.

The translation scheme consists of two production rules:

1. S → T R
2. R → T {print ();} R | ε
3. T → num {print (num.val);}

Let's break down the given input string and see how it is translated.

Input string: 9 5 2

S → T R:
- Apply production rule 1, S → T R, which expands the start symbol S into T R.
- T is the non-terminal symbol that represents a number and R is the non-terminal symbol that represents the remaining part of the input string.
- Now we have T R.

T → num {print (num.val);}
- Apply production rule 3, T → num {print (num.val);}, which expands T into num {print (num.val);}.
- num represents the first number in the input string, which is 9.
- {print (num.val);} is the action associated with T, which prints the value of num.
- So, the first number 9 is printed.

R → T {print ();} R
- Apply production rule 2, R → T {print ();} R, which expands R into T {print ();} R.
- T is the non-terminal symbol that represents a number, {print ();} is the action associated with T, and R is the non-terminal symbol that represents the remaining part of the input string.
- num represents the next number in the input string, which is 5.
- {print (num.val);} is the action associated with T, which prints the value of num.
- So, the second number 5 is printed.

R → T {print ();} R
- Apply production rule 2, R → T {print ();} R, which expands R into T {print ();} R.
- T is the non-terminal symbol that represents a number, {print ();} is the action associated with T, and R is the non-terminal symbol that represents the remaining part of the input string.
- num represents the last number in the input string, which is 2.
- {print (num.val);} is the action associated with T, which prints the value of num.
- So, the third number 2 is printed.

Therefore, the translation scheme will print the numbers in the input string as follows: 9 5 2.

Answer: Option B
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

Consider the translation scheme shown belowS → T RR → + T {print ('+');} R | εT → num {print (num.val);}Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will printa)9 + 5 + 2b)9 5 + 2 +c)9 5 2 + +d)+ + 9 5 2Correct answer is option 'B'. Can you explain this answer?
Question Description
Consider the translation scheme shown belowS → T RR → + T {print ('+');} R | εT → num {print (num.val);}Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will printa)9 + 5 + 2b)9 5 + 2 +c)9 5 2 + +d)+ + 9 5 2Correct answer is option 'B'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider the translation scheme shown belowS → T RR → + T {print ('+');} R | εT → num {print (num.val);}Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will printa)9 + 5 + 2b)9 5 + 2 +c)9 5 2 + +d)+ + 9 5 2Correct answer is option 'B'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the translation scheme shown belowS → T RR → + T {print ('+');} R | εT → num {print (num.val);}Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will printa)9 + 5 + 2b)9 5 + 2 +c)9 5 2 + +d)+ + 9 5 2Correct answer is option 'B'. Can you explain this answer?.
Solutions for Consider the translation scheme shown belowS → T RR → + T {print ('+');} R | εT → num {print (num.val);}Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will printa)9 + 5 + 2b)9 5 + 2 +c)9 5 2 + +d)+ + 9 5 2Correct answer is option 'B'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider the translation scheme shown belowS → T RR → + T {print ('+');} R | εT → num {print (num.val);}Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will printa)9 + 5 + 2b)9 5 + 2 +c)9 5 2 + +d)+ + 9 5 2Correct answer is option 'B'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the translation scheme shown belowS → T RR → + T {print ('+');} R | εT → num {print (num.val);}Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will printa)9 + 5 + 2b)9 5 + 2 +c)9 5 2 + +d)+ + 9 5 2Correct answer is option 'B'. Can you explain this answer?, a detailed solution for Consider the translation scheme shown belowS → T RR → + T {print ('+');} R | εT → num {print (num.val);}Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will printa)9 + 5 + 2b)9 5 + 2 +c)9 5 2 + +d)+ + 9 5 2Correct answer is option 'B'. Can you explain this answer? has been provided alongside types of Consider the translation scheme shown belowS → T RR → + T {print ('+');} R | εT → num {print (num.val);}Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will printa)9 + 5 + 2b)9 5 + 2 +c)9 5 2 + +d)+ + 9 5 2Correct answer is option 'B'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the translation scheme shown belowS → T RR → + T {print ('+');} R | εT → num {print (num.val);}Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string '9 + 5 + 2', this translation scheme will printa)9 + 5 + 2b)9 5 + 2 +c)9 5 2 + +d)+ + 9 5 2Correct answer is option 'B'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev